package com.xyz.controller;

import com.xyz.dao.StudentDao;
import com.xyz.service.StudentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/stu")
public class StudentController {
    //添加一个日志器
    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    @Autowired
    private static StudentService studentService;

    //映射一个action
    @RequestMapping("/list")
    public String list(ModelMap model){
        //输出日志文件
        logger.info("返回学生信息");
        //返回一个list.jsp这个视图
        model.addAttribute("stuname",studentService.getStudent(1).getName());
        return "list";
    }

    @RequestMapping("/hello")
    public String printHello(ModelMap model) {
        model.addAttribute("message", "Hello Spring MVC Framework!");
        return "hello";
    }


}
